<?php
class ViewHistoryService extends BaseDbService
{
	private $searchService;
	
	public function __construct()
	{
		$this->dao				= new ViewHistoryDao();
	}
	
	public function getCountByDate($d,$type)
	{
		$condition['where']['expression']		= 'type=:type and updated <="'.$d.' 23:59:59" and updated>="'.$d.' 00:00:00" ';
		$condition['where']['value']['type']		= $type;
		
		return $this->count($condition);
	}
	
	public function updateViewHistory($numId,$type,$num=1)
	{
		$condition['expression']		= 'num_id=:num_id and type=:type';
		$condition['value']['num_id']	= $numId;
		$condition['value']['type']		= $type;
		$tmp	= $this->fetch($condition);
		if(!$tmp)
		{
			return $this->add(array('num_id'=>$numId,'type'=>$type,'view_num'=>1));
		}
		else
		{
			return $this->dao->addViewNum($tmp['id'], $num);
		}
	}
	
	public function getRecentViewHistory($num,$fields='')
	{
		return $this->getList(array('type'=>1),'updated DESC',0,$num,$fields);
	}
	
	public function getRecentClickHistory($num,$fields='')
	{
		return $this->getList(array('type'=>2),'updated DESC',0,$num,$fields);
	}
	
	public function getRecentBuyHistory($num,$fields='')
	{
		return $this->getList(array('type'=>3),'updated DESC',0,$num,$fields);
	}
	
	public function getHotViewHistory($num,$fields='')
	{
		return $this->getList(array('type'=>1),'view_num DESC',0,$num,$fields);
	}
	
	public function getHotClickHistory($num,$fields='')
	{
		return $this->getList(array('type'=>2),'view_num DESC',0,$num,$fields);
	}
	
	public function getHotBuyHistory($num,$fields='')
	{
		return $this->getList(array('type'=>3),'view_num DESC',0,$num,$fields);
	}
}
?>